﻿using System;
using System.Web;
using System.Web.Routing;

namespace KeanuMvc.Reference.Routings {

    public class HttpHandlerRouteHandler : IRouteHandler {

        public IHttpHandler HttpHandler {
            get;
            private set;
        }

        public HttpHandlerRouteHandler(IHttpHandler httpHandler) {
            HttpHandler = httpHandler;
        }

        public IHttpHandler GetHttpHandler(RequestContext requestContext) {
            return HttpHandler;
        }
    }

    public class HttpHandlerRouteHandler<THttpHandler> : IRouteHandler where THttpHandler : IHttpHandler {
        readonly Func<RequestContext, THttpHandler> _handlerFactory;

        public HttpHandlerRouteHandler(Func<RequestContext, THttpHandler> handlerFactory) {
            _handlerFactory = handlerFactory;
        }

        public IHttpHandler GetHttpHandler(RequestContext requestContext) {
            return _handlerFactory(requestContext);
        }
    }
}
